home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / DJSRC111.ZIP / utils / dpmifix.c < prev    next >
C/C++ Source or Header  |  1993-05-31  |  2KB  |  83 lines

  1. #include <io.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <fcntl.h>
  5. #include <string.h>
  6. #define BUFSIZE 16384
  7.  
  8. #ifndef O_BINARY
  9. #define O_BINARY 0
  10. #endif
  11. #include "readspat.h"
  12.  
  13. main(argc, argv)
  14. int argc;
  15. char **argv;
  16. {
  17.   char *buffer;
  18.   int patchlen,npend,i,j,k,l,buflen;
  19.   int fil,nread;
  20.   long where;
  21.   FILE *fp;
  22.   int wild_in_prog, done;
  23.   char *wildname, *dire, *cp;
  24.   char nbuf[132];
  25. /*  struct ffblk ff; */
  26.  
  27.   patchlen = sizeof(original);
  28.   buffer = (char *)malloc(BUFSIZE + patchlen);
  29.  
  30.   wild_in_prog = 0;
  31.  
  32. loop:
  33.   if(!wild_in_prog) {
  34.     argv++;
  35.     argc--;
  36. /*    if(strpbrk(argv[0],"*?")) {
  37.       done = findfirst(argv[0], &ff, FA_RDONLY|FA_DIREC|FA_ARCH);
  38.       if(!done) {
  39.         wild_in_prog = 1;
  40.         wildname = argv[0];
  41.         strcpy(nbuf, wildname);
  42.         for (dire=cp=nbuf; *cp; cp++)
  43.           if (strchr("/\\:", *cp))
  44.             dire = cp + 1;
  45.         strcpy(dire, ff.ff_name);
  46.         argv[0] = &nbuf;
  47.       } 
  48.     } */
  49.   } else {
  50. /*    done = findnext(&ff);
  51.     if(done) { 
  52.       wild_in_prog = 0;
  53.       goto loop;
  54.     }
  55.     strcpy(dire, ff.ff_name); */
  56.   }
  57.   if(!argc)exit(0);
  58.   npend = 0;
  59.   fil = open(argv[0], O_RDWR|O_BINARY, 0);
  60.   if(fil < 0) {
  61.     fprintf(stderr,"%s not found.\n",argv[0]);
  62.     goto loop;
  63.   }
  64.   where = 0;
  65.   nread = read(fil, buffer, BUFSIZE);
  66.   while (nread > 0) {
  67.     buflen = nread + npend;
  68.     i = dopatch(buffer, buflen, original, match, patch, patchlen, &npend);
  69.     if (i >= 0) {
  70.       where = lseek(fil, (long)where+i, SEEK_SET);
  71.       write(fil, buffer+i, npend);
  72.       close(fil);
  73.       goto loop;
  74.     }
  75.     if (npend) memcpy(buffer, buffer+buflen-npend, npend);
  76.     where = lseek(fil, 0L, SEEK_CUR) - npend;
  77.     nread = read(fil, buffer+npend, BUFSIZE);
  78.   }
  79.   close(fil);
  80.   fprintf(stderr,"Patch code not found in %s\n",argv[0]);
  81.   goto loop;
  82. }
  83.